#pragma comment ( linker, "/STACK.64000000" )
#include <cstdio>

const int nmax = 100000;

int a[100010];
int si = 0;

void swap(int i, int j)
{
	int t = a[i]; a[i] = a[j]; a[j] = t;
}

void ShiftUp(int i)
{
	if (i == 1) return;
	if (a[i] > a[i / 2])
	{
		swap(i, i / 2);
		ShiftUp(i / 2);
	}
}

void ShiftDown(int i)
{
	if (2 * i > si) return;
	if (2 * i == si)
	{
		if (a[2 * i] > a[i])
			swap(2 * i, i);
		return;
	}
	int t = -1;
	if (a[2 * i + 1] >= a[2 * i])
		t = 2 * i + 1;
	if (a[2 * i] > a[2 * i + 1])
		t = 2 * i;
	if (t != -1 && a[t] > a[i]) 
	{
		swap(t, i);
		ShiftDown(t);
	}
	return;
};

void Insert(int x)
{
	si++;
	a[si] = x;
	ShiftUp(si);
}

int ExtractMax()
{
	int t = a[1];
	a[1] = a[si];
	a[si] = 0;
	si--;
	ShiftDown(1);
	return t;
}

int main ()
{
	freopen ( "pqueue.in", "r", stdin );
	freopen ( "pqueue.out", "w", stdout );
	int n;
	int x;
	scanf("%d", &n);
	for (int i = 0; i < n; i++ )
	{
		int f;
		scanf("%d", &f);
		if (f == 0)
		{
			scanf (" %d", &x);
			Insert(x);
		}
		else
			printf("%d\n", ExtractMax());
	}
}